<?php

namespace Application\Controller;

use System\Library\Control;
use System\Library\CURD\Model;
use Application\Model\User;
use linkcache\Cache;

class Account extends Control
{

  private $accountModel = null;

  public function __construct()
  {

    $this->accountModel = new Model();
  }

  public function login()
  {
    $loginResult = $this->accountModel->login();
    return $this->json($loginResult, 2);
  }

  public function curd_test(){
    $model = new Model();
    $user = new User();
    //$data = $model->table('user')->where(['age'=>23])->find();//查
    //$last_id = $model->table('user')->insert(['name'=>'aa','age'=>13]);//新增
    //$res = $model->table('user')->where(['name'=>'aa'])->update(['age'=>88]);//修改
    //$data = $model->table('user')->select();
    $data = $user->where(['user_id'=>1])->find();
    echo $user->lastsql;
    return $this->json($data);
  }

  /**
   * 缓存使用方式
   * 默认是文件缓存
   */
  public function cache_test(){
    $cache = Cache::getInstance();
    $cache->set('sayhi','Hello world 23!',10);
    echo $cache->get('sayhi');
  }
}
